﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace Venta
{
    public partial class Insertar: Form
    {
       
        MySqlConnection conexion = new MySqlConnection();
        string cnxstring;
        MySqlCommand cmd;
        public Insertar()
        {
            InitializeComponent();
        }
     

        private void btnguardar_Click(object sender, EventArgs e)
        {
            try
            {
                Conectar();
                //cmd=new MySqlCommand  ("insert into productos values(" +Int32 .Parse ( txtid.Text) + "','" + txtnombre.Text + "','" + txttipo.Text + "','" + Int32 .Parse (txtprecio.Text) + "')",conexion );
                cmd = new MySqlCommand("INSERT INTO productos VALUES('1', 'nombre','tipo','20')");
                cmd.ExecuteNonQuery();
                //conexion.Close();
            }
            catch
            { MessageBox.Show("No se pudieron Insertar"); }
       
        }
        private void Conectar()
        {
            try
            {
               
                cnxstring = "Server=127.0.0.1;Database=tienda;Uid=root; Pwd=mercedes;";
                conexion .ConnectionString =cnxstring ;
                conexion .Open ();
            }
            catch
            {
                MessageBox.Show("error en la conexion");
            }

        }
    }
}
